﻿using TestKeyboard.DriverStageHelper;

namespace TestKeyboard.PressKey
{
    public class PressKeyByWinIO : IPressKey
    {
        private EnumWindowsType mWinType;
        public bool Initialize(EnumWindowsType winType)
        {
            mWinType = winType;
            switch(mWinType)
            {
                case EnumWindowsType.Win64:
                    WinIO64.Initialize();
                    break;
                case EnumWindowsType.Win32:
                    WinIO32.Initialize();
                    break;
                default:
                    return false;
            }

            return true;
        }

        public void KeyDown(Keys key)
        {
            switch (mWinType)
            {
                case EnumWindowsType.Win64:
                    WinIO64.KeyDown((Keys)key);//按下
                    break;
                case EnumWindowsType.Win32:
                    WinIO32.KeyDown((Keys)key);//按下
                    break;
                default:
                    break;
            }
        }

        public void KeyPress(Keys key)
        {
            KeyDown(key);
            Thread.Sleep(10);
            KeyUp(key);
        }

        public void KeyUp(Keys key)
        {
            switch (mWinType)
            {
                case EnumWindowsType.Win64:
                    WinIO64.KeyUp((Keys)key);//按下
                    break;
                case EnumWindowsType.Win32:
                    WinIO32.KeyUp((Keys)key);//按下
                    break;
                default:
                    break;
            }
        }
    }
}
